# coding: UTF-8
# Filename : chain_replypost_api.py
# Company : imedia
# Author : zqz 
# -*-coding:utf-8 -*-
from api.common.common import *
from api.common import mysql,log,utils,httputils,const,xml_tpl, err_tpl
from django.http import HttpResponse
import chain_replypost_data_model
import time
	
#details list
def chain_replypost_list(request):
    '''
    用户在自由评论上与后台用户进行交互
    first : 查询此条评论的属性
    second; 插入对应字段
    '''
    #record log((frist action))
    httputils.footprint(request)
    #param
    comment_id = httputils.post(request, 'comment_id')#is customer id,more
    user_id = httputils.post(request, 'user_id')#is customer id,more
    content = httputils.post(request, 'content')#is customer id,more
    if not utils.is_num(comment_id): comment_id = 1
    if not utils.is_num(user_id): user_id = 1
    #Verification
    if validate(request):
        return validate(request)
    #models

    #first
    sql = '''
    select cus_id, target , target_id
    from chain_comment
    where id = %s
    '''
    param = [int(comment_id)]
    rsts = mysql.get(sql, param)
    if rsts != None:
	    time_d = time.time()
	    sql = '''
	    insert into chain_comment (cus_id,target, user_id, target_id,content,reply_id,created_at,source)
	    values
	    (%s,%s,%s,%s,%s,%s,%s,1)
	    '''
	    param_obj0 = rsts[0]
	    param_obj1 = rsts[1]
	    param_obj2 = rsts[2]
	    if param_obj0 == None : param_obj0 = ''
	    if param_obj1 == None : param_obj1 = ''
	    if param_obj2 == None : param_obj2 = ''
	    param = [int(param_obj0),int(param_obj1),int(user_id),int(param_obj2),content,comment_id,time_d]
	    mysql.insert(sql,param)
    output = ''
    output += chain_replypost_data_model.imedia_start 
    output += chain_replypost_data_model.imedia_body 
    output += chain_replypost_data_model.imedia_end
    return response(output)
